#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 101;
int da[maxn][maxn];
bool visited[maxn][maxn];
int n, m, px, py, dx = 0, dy = 1, ans;

int get_satisfaction(int x, int y)
{
	if (!visited[x][y]) {
		visited[x][y] = true;
		return da[x][y];
	}
	else
		return (da[x][y]/2);
}

bool inrange(int x, int y)
{
	return (1 <= x && x <= n && 1 <= y && y <= m);
}

int calc(int x1, int y1, int x2, int y2)
{
	int s = 0;
	if (x1 > x2 || y1 > y2) { swap(x1, x2); swap(y1, y2); }
	int dx = 0, dy = 1;
	if (x1 == x2) { dx = 1; dy = 0; }
	if (inrange(x2, y2))
		s += get_satisfaction(x2, y2);
	x2 += dx;  y2 += dy;
	if (inrange(x2, y2))
		s += get_satisfaction(x2, y2);
	return s;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++){
			char ch;
			cin >> ch;
			da[i+1][j+1] = ch - '0';
		}

	char ch;
	while (cin >> ch) {
		if (ch == 'L') {
			int t = dx;
			dx = -dy;
			dy = t;
		} else
		if (ch == 'R') {
			int t = dx;
			dx = dy;
			dy = -t;
		} else {
			ans += calc(px, py, px+dx, py+dy);
			px += dx;  py += dy;
		}
	}
	cout << ans << endl;
}
